﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataAccess;
using BastInfos.Helpers;
using BastInfos.Models.Home;
using DataAccess.Helpers;

namespace BastInfos.Controllers
{
	[HandleError]
	public class HomeController : Controller
	{
		public ActionResult Index()
		{
			return View(new IndexModel
			{
				Edito		= DataRepository.Get<Reference>().Where(r => r.ReferenceType == (byte)ReferenceType.Edito).First().Content,
				Intro		= DataRepository.Get<Reference>().Where(r => r.ReferenceType == (byte)ReferenceType.Intro).First().Content,
				Article		= DataRepository.Get<Article>().OrderByDescending(a => a.CreationDate).Where(a => a.Status == (byte)StatusType.Visible).First(a => a.DisplayHome),
				Articles	= DataRepository.Get<Article>().OrderByDescending(a => a.CreationDate).Where(a => a.Status == (byte)StatusType.Visible).Take(5),
				Events		= DataRepository.Get<Event>().OrderByDescending(e => e.CreationDate).Where(e => e.Status == (byte)StatusType.Visible).Take(5)
			});
		}

		public ActionResult About()
		{
			return View();
		}

		public ActionResult Contact()
		{
			return View(new ContactModel());
		}

		[HttpPost]
		public ActionResult ContactUs(ContactModel model)
		{
			if (ModelState.IsValid)
			{
				//TODO : SendMail
			}
			return View("Contact", model);
		}
	}
}
